package com.xnyzc.lhy.common.penum.order;


/**
 * @Author: huxuekuo
 * @Date: 2019-08-07 15:11
 * @Description:
 */
public enum EOrderStatus {

    waitingResponse(0, "等待应答"),
    orderTimeout(1, "订单超时异常（订单预约时间前1小时开始计算超过5分钟未点前往预约地点或预约时间开始10分钟后未点已就位或开始行程）"),//订单超时
    reassigned(2, "客服取消"),
    driverOrder(3, "司机已接单"),
    reservationLocation(4, "司机前往预约地点"),
    driverArrived(5, "司机已就位"),//司机已到达
    duringTrip(6, "行程中"),
    normalOrderPendingPayment(7, "行程结束已完成"),//正常订单待支付
    cancelPendingPayment(8, "取消行程待支付"),
    cancelOrdersFeesPaid(9, "应答前取消"),
    cancelOrderNoNeedPayment(10, "乘客取消"),//乘客取消订单
    abnormalEndOrder(11, "行程异常结束（客户强制取消）"),
    paymented(12, "已完成"),//已支付
    privateItinerary(13, "私用行程"),
    sendBill(14, "行程结束,待发起收款"),//司机发送账单
    examination(15, "待使用"),
    serviceClose(16, "客服关闭"),
    otherPlatformsAccept(17, "该订单已被其他平台受理"),
    driverCancelOrder(18, "司机取消订单"),
    servicceItineraryClose(19, "客服行程中关闭"),
    driverThrowOrder(20, "订单已申请改派"),//司机改派订单
    changeDriver(21, "司机改派"),
    orderStatusCheck(22, "订单状态校验"),
    officeCancelOrder(23,"供应商取消订单");

    public static CharteredOrderStatus getCharteredOrderType(int type){
        switch (type) {
            case 0:
                //已下单
                return CharteredOrderStatus.order;
            case 3:
                //已接单
                return CharteredOrderStatus.driverOrder;
            case 6:
                //服务中
                return CharteredOrderStatus.inOrder;
            case 12:
                //服务完成
                return CharteredOrderStatus.orderSucccess;
            case 23:
            case 10:
                //已取消
                return CharteredOrderStatus.cancelOrder;
            default:
                return CharteredOrderStatus.order;

        }

    }
    /**
     * 判断当前订单状态释放应该释放司机
     *
     * @return
     */
    public static boolean isFreedDriver(EOrderStatus orderStatus) {
        /**
         * 如果当前状态为行程中状态,不可以释放司机
         */
        if (orderStatus == driverOrder
                || orderStatus == waitingResponse
                || orderStatus == reservationLocation
                || orderStatus == driverArrived
                || orderStatus == duringTrip
                || orderStatus == sendBill
                || orderStatus == servicceItineraryClose) {
            return false;
        }
        return true;
    }

    /**
     * 判断是否为行程中的订单
     *
     * @param status
     * @return
     */
    public static boolean isDuringTrip(EOrderStatus status) {
        if (status == waitingResponse || status == duringTrip || status == privateItinerary || status == driverArrived || status == reservationLocation || status == driverOrder) {
            return true;
        }
        return false;
    }


    public static boolean cancelOrder(EOrderStatus status) {
        if (status == duringTrip || status == privateItinerary || status == sendBill) {
            return true;
        }
        return false;
    }

    /**
     * 判断订单是否在行程中
     *
     * @param status
     * @return true 在行程中 , false 不在行程中
     */
    public static boolean isReturn(EOrderStatus status) {
        if (status != normalOrderPendingPayment
                && status != cancelPendingPayment
                && status != cancelOrdersFeesPaid
                && status != cancelOrderNoNeedPayment
                && status != abnormalEndOrder
                && status != paymented
                && status != examination) {
            return true;
        }
        return false;
    }

    /**
     * 当前状态是否可以推送GPS
     *
     * @param status
     * @return
     */
    public static boolean isSendGps(EOrderStatus status) {
        if (status != normalOrderPendingPayment
                && status != waitingResponse
                && status != cancelPendingPayment
                && status != cancelOrdersFeesPaid
                && status != cancelOrderNoNeedPayment
                && status != abnormalEndOrder
                && status != paymented
                && status != examination
        ) {
            return true;
        }
        return false;
    }

    /**
     * 判断当前订单是否已支付
     *
     * @return
     */
    public static boolean isPay(EOrderStatus status) {
        if (status == paymented) {
            return true;
        }
        return false;
    }

    /**
     * 单纯判断是否是取消订单
     *
     * @param status 当前订单状态
     * @return true 为取消订单  false 为非取消订单
     */
    public static boolean isCancelOrder(EOrderStatus status) {
        if (status == cancelPendingPayment ||
                status == cancelOrdersFeesPaid ||
                status == cancelOrderNoNeedPayment || status == abnormalEndOrder) {
            return true;
        }
        return false;
    }


    /**
     * 判断订单是否取消
     *
     * @param status
     * @return true 该订单是取消订单 false 该订单非取消订单
     */
    public static boolean isCancel(EOrderStatus status) {
        if (status == cancelPendingPayment || status == cancelOrdersFeesPaid || status == cancelOrderNoNeedPayment || status == abnormalEndOrder || status == normalOrderPendingPayment || status == paymented) {
            return true;
        }
        return false;
    }

    /**
     * 判断订单状态是否可以继续调度
     * 只有 等待应答状态 可以继续调度
     *
     * @return 订单状态
     */
    public static boolean isNotDispatch(Integer status) {
        EOrderStatus byId = findById(status);
        // 没有这个订单状态,不可以调度
        if (null == byId) {
            return true;
        }
        //只有订单状态为等待应答,才可以继续调度
        if (byId.getType().equals(EOrderStatus.waitingResponse.getType())) {
            return false;
        }
        // 否则停止调度
        return true;
    }

    /**
     * 判断是否是进行中的状态
     *
     * @param status
     * @return
     */
    public static boolean isTrue(EOrderStatus status) {
        if (status == duringTrip || status == privateItinerary
        ) {
            return true;
        }
        return false;
    }


    private Integer type;
    private String value;

    EOrderStatus(Integer type, String value) {
        this.type = type;
        this.value = value;
    }

    public static EOrderStatus findById(Integer type) {
        if (null == type) {
            return null;
        }
        EOrderStatus[] values = EOrderStatus.values();
        for (EOrderStatus value : values) {
            if (value.type.equals(type)) {
                return value;
            }
        }
        return null;
    }


    public String getValue() {
        return this.value;
    }

    public Integer getType() {
        return this.type;
    }

    public int getTypeInt() {
        return this.type;
    }
}
